<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="http://mockjs.com/dist/mock.js"></script>
</head>
<body>

<div>
    <h1 id="mockjs">mockjs</h1>
</div>

<script type="text/javascript">

    //调用mock方法模拟数据
    
Mock.mock(
    'http://mockjs', {
        'ret': true,
        'msg': null,
        'data': [
            {
                "id": 1,
                "name": "技术部",
                "parentId": 0,
                "level": "0",
                "seq": 1,
                "remark": "技术部",
                "operator": "system",
                "operateTime": '@date("yyyy-MM-dd")',
                "operateIp": "127.0.0.1",
                "deptList": [
                    {
                        "id": 2,
                        "name": "后端开发",
                        "parentId": 1,
                        "level": "0.1",
                        "seq": 1,
                        "remark": "后端",
                        "operator": "system-update",
                        "operateTime": '@date("yyyy-MM-dd")',
                        "operateIp": "127.0.0.1",
                        "deptList": []
                    },
                    {
                        "id": 3,
                        "name": "前端开发",
                        "parentId": 1,
                        "level": "0.1",
                        "seq": 2,
                        "remark": "",
                        "operator": "system-update",
                        "operateTime": '@date("yyyy-MM-dd")',
                        "operateIp": "127.0.0.1",
                        "deptList": []
                    }
                ]
            },
            {
                "id": 12,
                "name": "客服部",
                "parentId": 0,
                "level": "0",
                "seq": 4,
                "remark": "",
                "operator": "Admin",
                "operateTime": 1508170975000,
                "operateIp": "0:0:0:0:0:0:0:1",
                "deptList": []
            }
        ]
    }
);

    //ajax请求
    $("#mockjs").click(function(){
        $.ajax({
            url        : "http://mockjs",    //请求的url地址
            dataType   : "json",   //返回格式为json
            async      : true, //请求是否异步，默认为异步，这也是ajax重要特性
            data       : {},    //参数值
            type       : "GET",   //请求方式
            beforeSend : function() {
                //请求前的处理
            },
            success: function(req) {
                //请求成功时处理
                console.log(req);
            },
            complete: function() {
                //请求完成的处理
            },
            error: function() {
                //请求出错处理
            }
        });
    });
</script>
</body>
</html>